package com.example.zwg;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.widget.ImageView;

import java.io.File;

public class RecognizerActivity extends Activity {
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        final int  TACK_PICTURE=0;
        ImageView imageView=null;
        if (requestCode==TACK_PICTURE){
            if (data!=null){
//                检查结果是否包含缩略图
                if (data.hasExtra("data")){
                    Bitmap thumbnail=data.getParcelableExtra("data");
                    imageView.setImageBitmap(thumbnail);
                }
            }else{
//                如果没有缩略图数据，这说明图像存储在目标输出URI中
//                下面为图片二次采样
                int width=imageView.getWidth();
                int height=imageView.getHeight();
                BitmapFactory.Options options=new BitmapFactory.Options();
                options.inJustDecodeBounds=true;
                File file=null;
                Uri outputFileUri=Uri.fromFile(file);
                BitmapFactory.decodeFile(outputFileUri.getPath());
                int imageWidth=options.outWidth;
                int imageHeight=options.outHeight;
//                确定将图像缩小多少
                int scaleFactor= Math.min(imageWidth/width,imageHeight/height);
//                将图像文件解码为图像大小以填充视图
                options.inJustDecodeBounds=false;
                options.inSampleSize=scaleFactor;
                options.inPurgeable=true;

                Bitmap bitmap=BitmapFactory.decodeFile(outputFileUri.getPath(),options);
                imageView.setImageBitmap(bitmap);
            }
        }
    }
}
